package com.atguigu.yygh.user.service.impl;


import com.atguigu.yygh.cmn.client.DictFeignClient;
import com.atguigu.yygh.enums.DictEnum;
import com.atguigu.yygh.model.user.Patient;
import com.atguigu.yygh.user.mapper.PatientMapper;
import com.atguigu.yygh.user.service.PatientService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 就诊人表 服务实现类
 * </p>
 *
 * @author atguigu
 * @since 2025-03-22
 */
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService {
    @Autowired
    private PatientMapper patientMapper;
    @Autowired
    private DictFeignClient dictFeignClient;
    @Override
    public List<Patient> getPatientList(Long userId) {
        List<Patient> patients = patientMapper.selectList(new QueryWrapper<Patient>().eq("user_id", userId));
        patients.forEach(this::packPatient);
        return patients;
    }

    @Override
    public Patient getPatientById(Long id) {
        Patient patient = patientMapper.selectById(id);
        packPatient(patient);
        return patient;
    }

    private void packPatient(Patient patient) {
            // 封装就诊人信息
        String certificatesTypeName = dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(), patient.getCertificatesType());
        String provinceName = dictFeignClient.getName(patient.getProvinceCode());
        String cityName = dictFeignClient.getName(patient.getCityCode());
        String districtName = dictFeignClient.getName(patient.getDistrictCode());
        Map<String, Object> param = patient.getParam();
        param.put("certificatesTypeString", certificatesTypeName);
        param.put("provinceString", provinceName);
        param.put("cityString", cityName);
        param.put("districtString", districtName);
        param.put("fullAddress",provinceName+cityName+districtName+patient.getAddress());
    }
}
